package com.luca.web.controller.system;

import com.luca.common.annotation.Log;
import com.luca.common.core.controller.BaseController;
import com.luca.common.core.domain.JsonResult;
import com.luca.common.enums.BusinessType;
import com.luca.common.utils.poi.ExcelUtil;
import com.luca.system.domain.SysTenant;
import com.luca.system.service.ISysTenantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import com.luca.common.core.page.TableDataInfo;

/**
 * 租户信息Controller
 * 
 * @author luca
 * @date 2020-12-25
 */
@RestController
@RequestMapping("/system/tenant")
public class SysTenantController extends BaseController {

    @Autowired
    private ISysTenantService sysTenantService;

    /**
     * 查询租户信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:tenant:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysTenant sysTenant) {
        startPage();
        List<SysTenant> list = sysTenantService.selectSysTenantList(sysTenant);
        return getDataTable(list);
    }

    /**
     * 导出租户信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:tenant:export')")
    @Log(title = "租户信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public JsonResult export(SysTenant sysTenant) {
        List<SysTenant> list = sysTenantService.selectSysTenantList(sysTenant);
        ExcelUtil<SysTenant> util = new ExcelUtil<SysTenant>(SysTenant.class);
        return util.exportExcel(list, "tenant");
    }

    /**
     * 获取租户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:tenant:query')")
    @GetMapping(value = "/{id}")
    public JsonResult getInfo(@PathVariable("id") Long id) {
        return JsonResult.success(sysTenantService.selectSysTenantById(id));
    }

    /**
     * 新增租户信息
     */
    @PreAuthorize("@ss.hasPermi('system:tenant:add')")
    @Log(title = "租户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public JsonResult add(@RequestBody SysTenant sysTenant) {
        sysTenantService.insertSysTenant(sysTenant);
        return JsonResult.success();
    }

    /**
     * 修改租户信息
     */
    @PreAuthorize("@ss.hasPermi('system:tenant:edit')")
    @Log(title = "租户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public JsonResult edit(@RequestBody SysTenant sysTenant) {
        sysTenantService.updateSysTenant(sysTenant);
        return JsonResult.success();
    }

    /**
     * 删除租户信息
     */
    @PreAuthorize("@ss.hasPermi('system:tenant:remove')")
    @Log(title = "租户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public JsonResult remove(@PathVariable Long[] ids) {
        sysTenantService.deleteSysTenantByIds(ids);
        return JsonResult.success();
    }

    /**
     * 修改租户状态
     */
    @PreAuthorize("@ss.hasPermi('system:tenant:edit')")
    @Log(title = "租户信息", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public JsonResult changeStatus(@RequestBody SysTenant sysTenant) {
        sysTenantService.updateTenantStatus(sysTenant);
        return JsonResult.success();
    }

}